package example

import (
	"gorm.io/gorm"
)

// Product 模型
type Product struct {
	gorm.Model
	Code  string
	Price uint
}

// CallSQLQuery db 查询调用
func CallSQLQuery(db *gorm.DB, code string) (uint, error) {
	product := &Product{}
	err := db.First(product, "code = ?", code).Error
	if err != nil {
		return 0, err
	}

	return product.Price, nil
}
